package com.pearadmin.pro.common.configure;

import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
import com.pearadmin.pro.common.configure.proprety.SwaggerProperty;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.oas.annotations.EnableOpenApi;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;


import javax.annotation.Resource;


/**
 * Swagger 文档配置
 *
 * Author: 就 眠 仪 式
 * CreateTime: 2021/04/01
 * */
@Slf4j
@Configuration
@EnableKnife4j
@EnableOpenApi
@EnableConfigurationProperties(SwaggerProperty.class)
public class SwaggerConfig  {



    @Resource
    private SwaggerProperty documentAutoProperties;

    @Bean
    public Docket docker(){
        log.info("Read document configuration information");
        return new Docket(DocumentationType.OAS_30)
                .apiInfo(apiInfo())
                .groupName(documentAutoProperties.getGroupName())
                .enable(documentAutoProperties.getEnable())
                .select()
                .apis(RequestHandlerSelectors.basePackage(documentAutoProperties.getScanPackage()))
                .build();
    }

    private ApiInfo apiInfo(){
        return  new ApiInfoBuilder()
                .title(documentAutoProperties.getTitle())
                .description(documentAutoProperties.getDescribe())
                .version(documentAutoProperties.getVersion())
                .termsOfServiceUrl(documentAutoProperties.getTermsOfServiceUrl())
                .contact(documentAutoProperties.getContact())
                .license(documentAutoProperties.getLicence())
                .licenseUrl(documentAutoProperties.getLicenceUrl())

                .build();
    }



}
